#
# spime_models.py
#
# This module creates a basic Google Datastore model for a spime.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2008 Jeremy Nelson

# Import statements
import cgi,logging
import datetime,os
import wsgiref.handlers

from google.appengine.ext import db
from google.appengine.api import users

class BaseSpime(db.Model):
    """BaseSpime provides a base model class for more detailed spime models"""
    last_modified = db.DateTimeProperty(auto_now=True)
    created_on = db.DateTimeProperty(auto_now_add=True)
    created_by = db.UserProperty()
    creation_location = db.GeoPtProperty()

class InformationTypes(db.Expando):
    """InformationTypes identifies the type of value being stored, can vary
       depending on the Spime's sensor data input"""
    value = db.StringProperty(required=True)
    created_by = db.UserProperty()
    created_on = db.DateTimeProperty(auto_now_add=True)

class SpimeJournal(db.Expando):
    """SpimeJournal records basic time and location of Spime"""
    spime = db.ReferenceProperty(BaseSpime)
    time_stamp = db.DateTimeProperty(auto_now_add=True)
    location = db.GeoPtProperty(required=True)
    info_type = db.ReferenceProperty(InformationTypes)
    value = db.StringProperty(required=True)
